﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dbPoll_Application.ViewModels.PollReportViewModel>" %>

 <h3><%=Model.name%></h3>
    <table class="reports">
        <tr class="reports">
            <th class="reports">#</th>
            <th class="reports">Question</th>
            <th class="reports">Answers</th>
        <% if (Model.selectedEntities.Count == 0)
           {            
             %>    
             <th class="reports">Number of Responses</th>
        <% }
           else
           {
               foreach (var entity in Model.selectedEntities)
               {
                 %>
                 <th class="reports"><%= entity.name%></th>
                 <%
               }
           } %>
             
        </tr>
        <% 
           int nextQuestionNumber = 1;
           foreach (var question in Model.questions)
           {
               if (question.deletionTime == null)
               {
                   nextQuestionNumber++; 
       %>
                
                    <tr class="reports">
                        <td class="reports"><%=question.questionNumber%></td>
                        <td class="reports"><%=question.question%></td>
                        <td class="reports">
                            <table>              
                                <%
                                    foreach (var answer in Model.responses[question])
                                    {
                                %>
                                        <tr><td><%=answer.Key%></td></tr>
                                <% 
                                    }
                                %>
                            </table>
                        </td>
                        <% if (Model.selectedEntities.Count == 0)
                           { %>
                        <td class="reports">
                            <table>
                                <%  
                            foreach (var answer in Model.responses[question])
                            {
                                %>
                                    <tr><td><%=answer.Value%></td></tr>
                                <% 
                            }
                                %>                        
                            </table>
                        </td>
                        <% }
                           else
                           { 
                               foreach (var entity in Model.selectedEntities)
                               {
                               
                                 %>
                                 <td class="reports">
                                     <table>
                                        <% foreach (var answer in Model.filteredResponses[question])
                                           {   %>
                                                <tr><td><%= answer.Value[entity.entityID] %></td></tr>
                                            <% 
                                        } %>
                                     </table>
                                </td>
                                 <%
                               }
                           } %>
                    </tr>
   
        <%
                }
            }
                     %>
   
   </table>